package com.ourteam.system.dao.impl;

import com.ourteam.system.dao.ISysMessageReadStatusDAO;
import com.ourteam.system.dao.SysMessageReadStatus;
import com.ourteam.system.dao.SysMessageReadStatusDAOQueryBean;

import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;

import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * Template Name : DAO服务对象
 * Template Version : 1
 * Template Last Modfiy Date : Fri Nov 17 11:00:11 CST 2017
 * Auto Generate Date : 2018-07-31 15:13:40
  * Warning ! This file will be overwrite when regenerate !
  *
 */
public class AbstractSysMessageReadStatusDAOJdbcImpl extends AbstractSpringDAO
    implements ISysMessageReadStatusDAO {
    public static final String[] ENTITY_FIELDS = new String[] {
            Id, SysMessageId, ReceiverId, ReadTime, Status, Remarks, IsDroped,
            ReceiverName, ReceiverAccount, SysMessageTitle, SysMessagePriority,
            SysMessageSendTime, SysMessageStatus, SysMessageContent,
            SysMessageSenderName, SysMessageSenderAccount, SysMessageSenderId
        };
    public static final String[] ENTITY_PROPERTIES = new String[] {
            _DataObjectProperty.Id, _DataObjectProperty.SysMessageId,
            _DataObjectProperty.ReceiverId, _DataObjectProperty.ReadTime,
            _DataObjectProperty.Status, _DataObjectProperty.Remarks,
            _DataObjectProperty.IsDroped, _DataObjectProperty.ReceiverName,
            _DataObjectProperty.ReceiverAccount,
            _DataObjectProperty.SysMessageTitle,
            _DataObjectProperty.SysMessagePriority,
            _DataObjectProperty.SysMessageSendTime,
            _DataObjectProperty.SysMessageStatus,
            _DataObjectProperty.SysMessageContent,
            _DataObjectProperty.SysMessageSenderName,
            _DataObjectProperty.SysMessageSenderAccount,
            _DataObjectProperty.SysMessageSenderId
        };
    public static final String[] ENTITY_PK_FIELDS = new String[] { Id };
    public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] { Id };
    public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {  };
    private static String relatedJoinSQL = null;
    private static String basicFilterSQL = null;
    private DataAccessObjectHelper<SysMessageReadStatus, SysMessageReadStatusDAOQueryBean> daoHelper;

    public AbstractSysMessageReadStatusDAOJdbcImpl() {
        super();
        daoHelper = new DataAccessObjectHelper<SysMessageReadStatus, SysMessageReadStatusDAOQueryBean>(this);
    }

    protected String getEntityName() {
        return EntityName;
    }

    protected String[] getEntityFields() {
        return ENTITY_FIELDS;
    }

    protected String[] getEntityProperties() {
        return ENTITY_PROPERTIES;
    }

    protected String[] getEntityPKFields() {
        return ENTITY_PK_FIELDS;
    }

    protected String[] getEntityAutoGenPKFields() {
        return ENTITY_AUTO_GEN_PK_FIELDS;
    }

    protected String[] getEntityUniqueFields() {
        return ENTITY_UNIQUE_FIELDS;
    }

    protected String getBaiscQueryFilter() {
        if (basicFilterSQL == null) {
            StringBuffer basicFilterSQLbuffer = new StringBuffer();

            basicFilterSQL = basicFilterSQLbuffer.toString();
        }

        return basicFilterSQL;
    }

    protected String getRelatedJoinSQL() {
        if (relatedJoinSQL == null) {
            StringBuffer relatedJoinSQLBuffer = new StringBuffer();

            relatedJoinSQLBuffer.append(" LEFT JOIN ")
                                .append(com.ourteam.system.dao.ISysUserDAO.EntityName)
                                .append(" SYS_USER ");

            relatedJoinSQLBuffer.append(" ON ( ");

            relatedJoinSQLBuffer.append(StringUtils.replace(
                    com.ourteam.system.dao.ISysUserDAO.Id,
                    com.ourteam.system.dao.ISysUserDAO.EntityName + ".",
                    "SYS_USER."));
            relatedJoinSQLBuffer.append(" = ").append(ReceiverId);

            relatedJoinSQLBuffer.append(" ) ");

            relatedJoinSQLBuffer.append(" LEFT JOIN ")
                                .append(com.ourteam.system.dao.ISysMessageDAO.EntityName)
                                .append(" SYS_MESSAGE ");

            relatedJoinSQLBuffer.append(" ON ( ");

            relatedJoinSQLBuffer.append(StringUtils.replace(
                    com.ourteam.system.dao.ISysMessageDAO.Id,
                    com.ourteam.system.dao.ISysMessageDAO.EntityName + ".",
                    "SYS_MESSAGE."));
            relatedJoinSQLBuffer.append(" = ").append(SysMessageId);

            relatedJoinSQLBuffer.append(" AND ");

            relatedJoinSQLBuffer.append(StringUtils.replace(
                    com.ourteam.system.dao.ISysMessageDAO.SenderId,
                    com.ourteam.system.dao.ISysMessageDAO.EntityName + ".",
                    "SYS_MESSAGE."));
            relatedJoinSQLBuffer.append(" = ").append(SysMessageSenderId);

            relatedJoinSQLBuffer.append(" ) ");

            relatedJoinSQLBuffer.append(" LEFT JOIN ")
                                .append(com.ourteam.system.dao.ISysUserDAO.EntityName)
                                .append(" SYS_MESSAGE_SENDER ");

            relatedJoinSQLBuffer.append(" ON ( ");

            relatedJoinSQLBuffer.append(" ) ");

            relatedJoinSQL = relatedJoinSQLBuffer.toString();
        }

        return relatedJoinSQL;
    }

    /**
         * Check Data Unique
         * @param aSysMessageReadStatus
         * @throws Exception
         */
    public boolean checkIsUnique(SysMessageReadStatus aSysMessageReadStatus)
        throws Exception {
        if (aSysMessageReadStatus == null) {
            return true;
        }

        List valueList = new ArrayList();

        List pkValueList = new ArrayList();

        pkValueList.add(aSysMessageReadStatus.getId());

        return isUnique(valueList.toArray(new Object[valueList.size()]),
            pkValueList.toArray(new Object[pkValueList.size()]));
    }

    /**
     * Insert Data
     * @param aSysMessageReadStatus
     * @throws Exception
     */
    public void insert(SysMessageReadStatus aSysMessageReadStatus)
        throws Exception {
        super.doInsert(aSysMessageReadStatus);
    }

    /**
         * Batch Insert Datas
         * @param aSysMessageReadStatus
         * @throws Exception
         */
    public void batchInsert(SysMessageReadStatus[] aSysMessageReadStatuss)
        throws Exception {
        super.doBatchInsert(aSysMessageReadStatuss);
    }

    /**
         * Delete Data
         * @param  final long id         *
         * @throws Exception
         */
    public void delete(final long id) throws Exception {
        super.doDeleteById(new Object[] { new Long(id) });
    }

    /**
     * Delete Datas
     * @param queryBean
     * @throws Exception
     */
    public void delete(SysMessageReadStatusDAOQueryBean queryBean)
        throws Exception {
        super.doDeleteByQuery(queryBean);
    }

    public void delete(SysMessageReadStatus aSysMessageReadStatus)
        throws Exception {
        delete(aSysMessageReadStatus.getId());
    }

    /**
     * Update Data Selective
     * @param aSysMessageReadStatus
     * @throws Exception
     */
    public void update(SysMessageReadStatus aSysMessageReadStatus)
        throws Exception {
        if (aSysMessageReadStatus.getId() == 0) {
            throw new Exception(
                "Can not update object data whith out primary key value");
        }

        super.doUpdate(aSysMessageReadStatus);

        SysMessageReadStatus tempObj = findById(aSysMessageReadStatus.getId());

        if (tempObj != null) {
            PropertyUtils.copyProperties(aSysMessageReadStatus, tempObj);
        }
    }

    /**
     * Batch Update Datas
     * @param aSysMessageReadStatuss[]
     * @throws Exception
     */
    public void batchUpdate(SysMessageReadStatus[] aSysMessageReadStatuss)
        throws Exception {
        super.doBatchUpdate(aSysMessageReadStatuss);
    }

    /**
         * Update Data By Condictions
         * @param aSysMessageReadStatus
         * @param aValueCriteria
         * @param aTransaction
         * @throws Exception
         */
    public void update(SysMessageReadStatus aSysMessageReadStatus,
        SysMessageReadStatusDAOQueryBean aQueryBean) throws Exception {
        super.doUpdateByQuery(aSysMessageReadStatus, aQueryBean);
    }

    /**
     * Update Data By Condictions
     * @param aQueryBean
     * @throws Exception
     */
    public void update(SysMessageReadStatusDAOQueryBean aQueryBean)
        throws Exception {
        super.doUpdateByQuery(aQueryBean);
    }

    protected void checkNullValue(SysMessageReadStatus aSysMessageReadStatus)
        throws Exception {
        if (aSysMessageReadStatus.getReadTime() == null) {
            throw new Exception(
                "The SysMessageReadStatus.readTime value is not allow NULL");
        }

        if (aSysMessageReadStatus.getStatus() == null) {
            throw new Exception(
                "The SysMessageReadStatus.status value is not allow NULL");
        }

        if (aSysMessageReadStatus.getRemarks() == null) {
            throw new Exception(
                "The SysMessageReadStatus.remarks value is not allow NULL");
        }

        if (aSysMessageReadStatus.getReceiverName() == null) {
            throw new Exception(
                "The SysMessageReadStatus.receiverName value is not allow NULL");
        }

        if (aSysMessageReadStatus.getReceiverAccount() == null) {
            throw new Exception(
                "The SysMessageReadStatus.receiverAccount value is not allow NULL");
        }

        if (aSysMessageReadStatus.getSysMessageTitle() == null) {
            throw new Exception(
                "The SysMessageReadStatus.sysMessageTitle value is not allow NULL");
        }

        if (aSysMessageReadStatus.getSysMessageSenderName() == null) {
            throw new Exception(
                "The SysMessageReadStatus.sysMessageSenderName value is not allow NULL");
        }

        if (aSysMessageReadStatus.getSysMessageSenderAccount() == null) {
            throw new Exception(
                "The SysMessageReadStatus.sysMessageSenderAccount value is not allow NULL");
        }

        if (aSysMessageReadStatus.getSysMessagePriority() == null) {
            throw new Exception(
                "The SysMessageReadStatus.sysMessagePriority value is not allow NULL");
        }

        if (aSysMessageReadStatus.getSysMessageSendTime() == null) {
            throw new Exception(
                "The SysMessageReadStatus.sysMessageSendTime value is not allow NULL");
        }

        if (aSysMessageReadStatus.getSysMessageStatus() == null) {
            throw new Exception(
                "The SysMessageReadStatus.sysMessageStatus value is not allow NULL");
        }

        if (aSysMessageReadStatus.getIsDroped() == null) {
            throw new Exception(
                "The SysMessageReadStatus.isDroped value is not allow NULL");
        }

        if (aSysMessageReadStatus.getSysMessageContent() == null) {
            throw new Exception(
                "The SysMessageReadStatus.sysMessageContent value is not allow NULL");
        }
    }

    /**
     * Get Data By ID
     * @param  final long id         * @return  ${businessObject.name}
     * @throws Exception
     */
    public SysMessageReadStatus findById(final long id)
        throws Exception {
        SysMessageReadStatusDAOQueryBean queryBean = new SysMessageReadStatusDAOQueryBean();

        SysMessageReadStatusDAOQueryBean.Criteria criteria = queryBean.createCriteria();

        criteria.andIdEqualTo(id);

        //queryBean.setDistinct(true);
        SysMessageReadStatus[] SysMessageReadStatuss = query(queryBean);

        if (SysMessageReadStatuss.length == 0) {
            return null;
        } else {
            return SysMessageReadStatuss[0];
        }
    }

    /**
         * Query Data
         * @param queryBean
         * @return SysMessageReadStatus[]
         * @throws Exception
         */
    public SysMessageReadStatus[] query(
        SysMessageReadStatusDAOQueryBean queryBean) throws Exception {
        List result = super.doQuery(queryBean,
                new JdbcSysMessageReadStatusRowMapper());

        return (SysMessageReadStatus[]) result.toArray(new SysMessageReadStatus[result.size()]);
    }

    /**
     * Query ${businessObject.name} Selective
     * @param queryBean
     * @return Map[]
     * @model
     * @throws Exception
     */
    public Map<String, Object>[] querySelective(
        SysMessageReadStatusDAOQueryBean queryBean) throws Exception {
        if (queryBean.getSelectProperties().isEmpty()) {
            queryBean.addAllSelectProperties();
        }

        return super.doQuerySelective(queryBean);
    }

    /**
     * Query Data Count
     * @param queryBean
     * @return int
     * @throws Exception
     */
    public int queryCount(SysMessageReadStatusDAOQueryBean queryBean)
        throws Exception {
        return super.doQueryCount(queryBean);
    }

    public void synchronize(SysMessageReadStatus[] aSysMessageReadStatuss,
        SysMessageReadStatusDAOQueryBean queryBean) throws Exception {
        daoHelper.synchronize(aSysMessageReadStatuss, queryBean);
    }

    public void synchronize(SysMessageReadStatus[] aSysMessageReadStatuss,
        SysMessageReadStatusDAOQueryBean queryBean,
        net.dao.IDataAccessInterface.ISynchronizeCallback<SysMessageReadStatus> callBack)
        throws Exception {
        daoHelper.synchronize(aSysMessageReadStatuss, queryBean, callBack);
    }

    public static class JdbcSysMessageReadStatusRowMapper implements RowMapper<SysMessageReadStatus> {
        public SysMessageReadStatus mapRow(ResultSet resultSet, int arg1)
            throws SQLException {
            SysMessageReadStatus object = new SysMessageReadStatus();

            int columnIndex = 1;

            int __dataType;

            try {
                Object id = null;

                id = resultSet.getObject(columnIndex++);

                object.setIdNull(resultSet.getBoolean(columnIndex++));

                if (id != null) {
                    setBeanValue(object, _DataObjectProperty.Id, id);
                }

                Object sysMessageId = null;

                sysMessageId = resultSet.getObject(columnIndex++);

                object.setSysMessageIdNull(resultSet.getBoolean(columnIndex++));

                if (sysMessageId != null) {
                    setBeanValue(object, _DataObjectProperty.SysMessageId,
                        sysMessageId);
                }

                Object receiverId = null;

                receiverId = resultSet.getObject(columnIndex++);

                object.setReceiverIdNull(resultSet.getBoolean(columnIndex++));

                if (receiverId != null) {
                    setBeanValue(object, _DataObjectProperty.ReceiverId,
                        receiverId);
                }

                Object readTime = null;

                __dataType = resultSet.getMetaData().getColumnType(columnIndex);

                if ((__dataType == java.sql.Types.DATE) ||
                        (__dataType == java.sql.Types.TIME) ||
                        (__dataType == java.sql.Types.TIMESTAMP)) {
                    readTime = resultSet.getTimestamp(columnIndex++);
                } else {
                    readTime = resultSet.getObject(columnIndex++);
                }

                object.setReadTimeNull(resultSet.getBoolean(columnIndex++));

                if (readTime != null) {
                    setBeanValue(object, _DataObjectProperty.ReadTime, readTime);
                }

                Object status = null;

                status = resultSet.getObject(columnIndex++);

                object.setStatusNull(resultSet.getBoolean(columnIndex++));

                if (status != null) {
                    setBeanValue(object, _DataObjectProperty.Status, status);
                }

                Object remarks = null;

                remarks = resultSet.getObject(columnIndex++);

                object.setRemarksNull(resultSet.getBoolean(columnIndex++));

                if (remarks != null) {
                    setBeanValue(object, _DataObjectProperty.Remarks, remarks);
                }

                Object isDroped = null;

                isDroped = resultSet.getObject(columnIndex++);

                object.setIsDropedNull(resultSet.getBoolean(columnIndex++));

                if (isDroped != null) {
                    setBeanValue(object, _DataObjectProperty.IsDroped, isDroped);
                }

                Object receiverName = null;

                receiverName = resultSet.getObject(columnIndex++);

                object.setReceiverNameNull(resultSet.getBoolean(columnIndex++));

                if (receiverName != null) {
                    setBeanValue(object, _DataObjectProperty.ReceiverName,
                        receiverName);
                }

                Object receiverAccount = null;

                receiverAccount = resultSet.getObject(columnIndex++);

                object.setReceiverAccountNull(resultSet.getBoolean(
                        columnIndex++));

                if (receiverAccount != null) {
                    setBeanValue(object, _DataObjectProperty.ReceiverAccount,
                        receiverAccount);
                }

                Object sysMessageTitle = null;

                sysMessageTitle = resultSet.getObject(columnIndex++);

                object.setSysMessageTitleNull(resultSet.getBoolean(
                        columnIndex++));

                if (sysMessageTitle != null) {
                    setBeanValue(object, _DataObjectProperty.SysMessageTitle,
                        sysMessageTitle);
                }

                Object sysMessagePriority = null;

                sysMessagePriority = resultSet.getObject(columnIndex++);

                object.setSysMessagePriorityNull(resultSet.getBoolean(
                        columnIndex++));

                if (sysMessagePriority != null) {
                    setBeanValue(object,
                        _DataObjectProperty.SysMessagePriority,
                        sysMessagePriority);
                }

                Object sysMessageSendTime = null;

                __dataType = resultSet.getMetaData().getColumnType(columnIndex);

                if ((__dataType == java.sql.Types.DATE) ||
                        (__dataType == java.sql.Types.TIME) ||
                        (__dataType == java.sql.Types.TIMESTAMP)) {
                    sysMessageSendTime = resultSet.getTimestamp(columnIndex++);
                } else {
                    sysMessageSendTime = resultSet.getObject(columnIndex++);
                }

                object.setSysMessageSendTimeNull(resultSet.getBoolean(
                        columnIndex++));

                if (sysMessageSendTime != null) {
                    setBeanValue(object,
                        _DataObjectProperty.SysMessageSendTime,
                        sysMessageSendTime);
                }

                Object sysMessageStatus = null;

                sysMessageStatus = resultSet.getObject(columnIndex++);

                object.setSysMessageStatusNull(resultSet.getBoolean(
                        columnIndex++));

                if (sysMessageStatus != null) {
                    setBeanValue(object, _DataObjectProperty.SysMessageStatus,
                        sysMessageStatus);
                }

                Object sysMessageContent = null;

                sysMessageContent = resultSet.getObject(columnIndex++);

                object.setSysMessageContentNull(resultSet.getBoolean(
                        columnIndex++));

                if (sysMessageContent != null) {
                    setBeanValue(object, _DataObjectProperty.SysMessageContent,
                        sysMessageContent);
                }

                Object sysMessageSenderName = null;

                sysMessageSenderName = resultSet.getObject(columnIndex++);

                object.setSysMessageSenderNameNull(resultSet.getBoolean(
                        columnIndex++));

                if (sysMessageSenderName != null) {
                    setBeanValue(object,
                        _DataObjectProperty.SysMessageSenderName,
                        sysMessageSenderName);
                }

                Object sysMessageSenderAccount = null;

                sysMessageSenderAccount = resultSet.getObject(columnIndex++);

                object.setSysMessageSenderAccountNull(resultSet.getBoolean(
                        columnIndex++));

                if (sysMessageSenderAccount != null) {
                    setBeanValue(object,
                        _DataObjectProperty.SysMessageSenderAccount,
                        sysMessageSenderAccount);
                }

                Object sysMessageSenderId = null;

                sysMessageSenderId = resultSet.getObject(columnIndex++);

                object.setSysMessageSenderIdNull(resultSet.getBoolean(
                        columnIndex++));

                if (sysMessageSenderId != null) {
                    setBeanValue(object,
                        _DataObjectProperty.SysMessageSenderId,
                        sysMessageSenderId);
                }

                return object;
            } catch (Exception e) {
                throw new SQLException(e.getMessage());
            }
        }
    }
}
